package com.xuemeng.web;

import com.xuemeng.entity.*;
import com.xuemeng.entity.vo.customerVO;
import com.github.pagehelper.PageHelper;
import com.xuemeng.model.JqgridBean;
import com.xuemeng.model.PageRusult;
import com.xuemeng.service.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.*;


/**
 * @author xuemeng
 * @date 2018/12/12 22:03
 * 客户操作类
 */
@Controller
@RequestMapping("/customer")
public class customerController {

        @Resource
        private TcustomerService tcustomerService;
        @Resource
        private TgroupService groupService;
        @Resource
        private TtrailService ttrailService;
        @Resource
        private TuserService tuserService;

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        /**
         * 进入客户主页面
         *
         * @return
         */
        @RequestMapping("/toCustomerManage")
        @RequiresPermissions(value = {"客户管理"})
        public String toGroupManage() {

                return "content/customer";
        }
        /**
         * 进入我的客户主页面
         *
         * @return
         */
        @RequestMapping("/toMyCustomerManage")
        @RequiresPermissions(value = {"我的客户"})
        public String toMyCustomerManage() {

                return "content/myCustomer";
        }
        /**
         * 进入我的客户跟进主页面
         *
         * @return
         */
        @RequestMapping("/toTrailCustomerManage")
        @RequiresPermissions(value = {"客户跟进"})
        public String toTrailCustomerManage() {

                return "content/trailCustomer";
        }
        /**
         * 分页查询客户信息---公共的
         */

        @ResponseBody
        @RequestMapping(value = "/list")
        @RequiresPermissions(value = {"客户管理"})
        public Map<String, Object> list(JqgridBean jqgridbean) throws Exception {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
                LinkedHashMap<String, Object> datamap = new LinkedHashMap<String, Object>();
                Example troleExample = new Example(Tcustomer.class);
                //排序
                troleExample.setOrderByClause("create_time DESC");
               // troleExample.setOrderByClause("update_time DESC");
               // Example.Criteria criteria = troleExample.and();
                //userId  是空的代表公共的客户资源--客户池--公海
                troleExample.and().andIsNull("userId").orEqualTo("userId","");
                if (StringUtils.isNotEmpty(jqgridbean.getSearchField())) {
                        if ("linkman".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("linkman", jqgridbean.getSearchString());
                        }
                        if ("qq".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("qq", jqgridbean.getSearchString());
                        }
                        if ("wx".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("wx", jqgridbean.getSearchString());
                        }
                        if ("tel".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("tel", jqgridbean.getSearchString());
                        }
                        if ("tel2".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("tel2", jqgridbean.getSearchString());
                        }
                        if ("tel3".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("tel3", jqgridbean.getSearchString());
                        }
                        if ("groupName".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("groupName", jqgridbean.getSearchString());
                        }
                }

                PageHelper.startPage(jqgridbean.getPage(), jqgridbean.getLength());
                List<Tcustomer> customerList = tcustomerService.selectByExample(troleExample);
                PageRusult<Tcustomer> pageRusult = new PageRusult<Tcustomer>(customerList);

                resultmap.put("currpage", String.valueOf(pageRusult.getPageNum()));
                resultmap.put("totalpages", String.valueOf(pageRusult.getPages()));
                resultmap.put("totalrecords", String.valueOf(pageRusult.getTotal()));
                resultmap.put("datamap", customerList);

                return resultmap;
        }
        /**
         * 分页查询客户信息---个人客户
         */

        @ResponseBody
        @RequestMapping(value = "/myList")
        @RequiresPermissions(value = {"客户管理"})
        public Map<String, Object> mylist(JqgridBean jqgridbean, HttpServletRequest request) throws Exception {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
                LinkedHashMap<String, Object> datamap = new LinkedHashMap<String, Object>();

                Example troleExample = new Example(Tcustomer.class);
                //排序
                troleExample.setOrderByClause("create_time DESC");
               // troleExample.setOrderByClause("update_time DESC");
                //Example.Criteria criteria = troleExample.and();
                //获取当前登录用户信息
                Tuser user=(Tuser) request.getSession().getAttribute("currentUser");
                Trole role=(Trole)request.getSession().getAttribute("currentRole");
                //userId  非空代表每个人客户资源
                //System.out.println("================"+role.getName()+"====================");
                if (role.getName().equalsIgnoreCase("业务员角色")) {
                        troleExample.and().andEqualTo("userId", user.getId());
                }
                if (role.getName().equalsIgnoreCase("部门主管角色")) {
                        Example userExample = new Example(Tuser.class);
                        Example.Criteria cri = userExample.and();
                        cri.andEqualTo("deptId",user.getDeptId());
                        List<Tuser> userList = tuserService.selectByExample(userExample);
                        Collection<String> a = new ArrayList<String>();
                        for (Tuser tuser:userList){
                                a.add(tuser.getId()+"");
                        }
                       // Iterator<String> iterator=a.iterator();
                        troleExample.and().andIn("userId",a);
                }
                if (role.getName().equalsIgnoreCase("总经理角色") || role.getName().equalsIgnoreCase("管理员")) {
                        troleExample.and().andIsNotNull("userId").andNotEqualTo("userId", "");
                }

                if (role.getName().equalsIgnoreCase("售后服务员")){
                        troleExample.and().andIsNotNull("userId").andNotEqualTo("userId","");
                        troleExample.and().andLike("groupName","A");
                }else{
                        if (StringUtils.isNotEmpty(jqgridbean.getSearchField())) {
                                if ("groupName".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                        troleExample.and().andLike("groupName", jqgridbean.getSearchString());
                                }
                        }
                }

                if (StringUtils.isNotEmpty(jqgridbean.getSearchField())) {
                        if ("linkman".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("linkman", jqgridbean.getSearchString());
                        }
                        if ("qq".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("qq", jqgridbean.getSearchString());
                        }
                        if ("qq2".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("qq2", jqgridbean.getSearchString());
                        }
                        if ("wx".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("wx", jqgridbean.getSearchString());

                        }
                        if ("wx2".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("wx2", jqgridbean.getSearchString());
                        }
                        if ("tel".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("tel", jqgridbean.getSearchString());
                        }
                        if ("tel2".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("tel2", jqgridbean.getSearchString());
                        }
                        if ("tel3".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("tel3", jqgridbean.getSearchString());
                        }
                        if ("userName".equalsIgnoreCase(jqgridbean.getSearchField())) {
                                troleExample.and().andLike("userName", jqgridbean.getSearchString());
                        }
                }

                PageHelper.startPage(jqgridbean.getPage(), jqgridbean.getLength());
                List<Tcustomer> customerList = tcustomerService.selectByExample(troleExample);
                PageRusult<Tcustomer> pageRusult = new PageRusult<Tcustomer>(customerList);

                resultmap.put("currpage", String.valueOf(pageRusult.getPageNum()));
                resultmap.put("totalpages", String.valueOf(pageRusult.getPages()));
                resultmap.put("totalrecords", String.valueOf(pageRusult.getTotal()));
                resultmap.put("datamap", customerList);

                return resultmap;
        }
        /**
         * 分页查询客户信息---客户跟进
         */

        @ResponseBody
        @RequestMapping(value = "/trailList")
        @RequiresPermissions(value = {"客户跟进"})
        public Map<String, Object> trailList(JqgridBean jqgridbean, HttpServletRequest request) throws Exception {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
                LinkedHashMap<String, Object> datamap = new LinkedHashMap<String, Object>();

                List<Tcustomer> tcustomerList=new ArrayList<>();
                //获取当前登录用户信息
                Tuser user=(Tuser) request.getSession().getAttribute("currentUser");

                        //获取客户信息
                        Example customer = new Example(Tcustomer.class);

                         //排序
                        customer.setOrderByClause("create_time DESC");
                        customer.setOrderByClause("update_time DESC");
                        //userId  非空代表每个人客户资源
                        customer.and().andEqualTo("userId",user.getId());
                        List<Tcustomer> clist = tcustomerService.selectByExample(customer);
                        if (clist.size()>0){
                                for(Tcustomer tc:clist){
                                        Example trail = new Example(Ttrail.class);
                                        trail.and().andEqualTo("customerId",tc.getId());
                                        String day1=format2.format(new Date());
                                        Calendar c = Calendar.getInstance();
                                        c.setTime(new Date());
                                        c.add(Calendar.DAY_OF_MONTH, 7);// 今天+7天
                                        String day2=format2.format(c.getTime());
                                         trail.and().andBetween("nextTime",day1,day2);
                                        //trail.and().andLessThanOrEqualTo("nextTime",day2);
                                        //trail.and().andGreaterThanOrEqualTo("nextTime",day1);
                                        List<Ttrail> listTrail =ttrailService .selectByExample(trail);
                                        //如果有需要1天内跟进的客户，则返回客户
                                        if (listTrail!=null&& listTrail.size()>0){
                                                tcustomerList.add(tc);
                                        }
                                }
                        }
                PageHelper.startPage(jqgridbean.getPage(), jqgridbean.getLength());
                PageRusult<Tcustomer> pageRusult = new PageRusult<Tcustomer>(tcustomerList);

                resultmap.put("currpage", String.valueOf(pageRusult.getPageNum()));
                resultmap.put("totalpages", String.valueOf(pageRusult.getPages()));
                resultmap.put("totalrecords", String.valueOf(pageRusult.getTotal()));
                resultmap.put("datamap", tcustomerList);

                return resultmap;
        }
        /**
         *修改客户对应的业务员
         * @param customer
         * @return
         */
        @ResponseBody
        @RequestMapping(value = "/changeCustomerUser")
        @RequiresPermissions(value = {"客户管理"})
        public Map<String, Object> changeCustomerUser(Tcustomer customer) {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();

                if ((customer.getGroupId() == null || customer.getGroupName()==null) ) {
                        resultmap.put("state", "fail");
                        resultmap.put("mesg", "请选择用户");
                        return resultmap;
                }
                if ( customer.getGroupId()==customer.getGroupName()) {
                        resultmap.put("state", "fail");
                        resultmap.put("mesg", "不能选择相同的用户");
                        return resultmap;
                }
                try {
                        Example troleExample = new Example(Tcustomer.class);
                        troleExample.and().andEqualTo("userId",customer.getGroupId());
                        Tuser user=tuserService.selectByKey(Integer.parseInt(customer.getGroupName()));
                        List<Tcustomer> rolelist = tcustomerService.selectByExample(troleExample);
                        if (rolelist.size()>0) {
                                for (Tcustomer tcustomer : rolelist) {
                                        tcustomer.setUserId(user.getId()+"");
                                        tcustomer.setUserName(user.getTrueName()+"");
                                        tcustomerService.updateNotNull(tcustomer);
                                }
                        }else{
                                resultmap.put("state", "fail");
                                resultmap.put("mesg", "没有对应的客户");
                                return resultmap;
                        }



                        resultmap.put("state", "success");
                        resultmap.put("mesg", "操作成功");
                        return resultmap;
                } catch (Exception e) {
                        e.printStackTrace();
                        resultmap.put("state", "fail");
                        resultmap.put("mesg", "操作失败，系统异常");
                        return resultmap;
                }
        }
        /**
         * 添加公共客户
         * @param customer
         * @return
         */
        @ResponseBody
        @RequestMapping(value = "/addUpdateCustomer")
        @RequiresPermissions(value = {"客户管理"})
        public Map<String, Object> addUpdateGroup(Tcustomer customer) {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
                try {
                        if (customer.getId() == null) {//新建
                                //首先判断用户名是否可用
                                Example troleExample = new Example(Tcustomer.class);
                                if (customer.getTel() != "") {
                                        troleExample.or().andEqualTo("tel", customer.getTel());
                                }
                                if (customer.getWx() != ""){
                                        troleExample.or().andEqualTo("wx", customer.getWx());
                        }
                                if (customer.getQq()!="") {
                                        troleExample.or().andEqualTo("qq", customer.getQq());
                                }
                                List<Tcustomer> rolelist = tcustomerService.selectByExample(troleExample);
                                if (rolelist != null && rolelist.size() > 0) {
                                        resultmap.put("state", "fail");
                                        resultmap.put("mesg", "当前客户已存在");
                                        return resultmap;
                                }
                                customer.setCreateTime(format.format(new Date()));
                                tcustomerService.saveNotNull(customer);
                        } else {//编辑
                                Tcustomer oldObject = tcustomerService.selectByKey(customer.getId());
                                if (oldObject == null) {
                                        resultmap.put("state", "fail");
                                        resultmap.put("mesg", "当前客户不存在");
                                        return resultmap;
                                } else {
                                        customer.setUpdateTime(format.format(new Date()));
                                        tcustomerService.updateNotNull(customer);
                                }
                        }
                        resultmap.put("state", "success");
                        resultmap.put("mesg", "操作成功");
                        return resultmap;
                } catch (Exception e) {
                        e.printStackTrace();
                        resultmap.put("state", "fail");
                        resultmap.put("mesg", "操作失败，系统异常");
                        return resultmap;
                }
        }

        @ResponseBody
        @RequestMapping(value = "/addUpdateCustomer02")
        @RequiresPermissions(value = {"我的客户"})
        public Map<String, Object> addUpdateGroup02(Tcustomer customer,HttpServletRequest request) {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
                Tuser user=(Tuser)request.getSession().getAttribute("currentUser");
                try {
                        if (customer.getId() == null) {//新建
                                //首先判断用户名是否可用
                                Example troleExample = new Example(Tcustomer.class);
                                if (customer.getTel() != "") {
                                        troleExample.or().andEqualTo("tel", customer.getTel());
                                }
                                if (customer.getWx() != ""){
                                        troleExample.or().andEqualTo("wx", customer.getWx());
                                }
                                if (customer.getQq()!="") {
                                        troleExample.or().andEqualTo("qq", customer.getQq());
                                }
                                List<Tcustomer> rolelist = tcustomerService.selectByExample(troleExample);
                                if (rolelist != null && rolelist.size() > 0) {
                                        resultmap.put("state", "fail");
                                        resultmap.put("mesg", "当前客户已存在");
                                        return resultmap;
                                }
                                customer.setUserId(user.getId()+"");
                                customer.setUserName(user.getTrueName());
                                customer.setCreateTime(format.format(new Date()));
                                tcustomerService.saveNotNull(customer);
                        } else {//编辑
                                Tcustomer oldObject = tcustomerService.selectByKey(customer.getId());
                                if (oldObject == null) {
                                        resultmap.put("state", "fail");
                                        resultmap.put("mesg", "当前客户不存在");
                                        return resultmap;
                                } else {
                                        customer.setUpdateTime(format.format(new Date()));
                                        customer.setUserId(user.getId()+"");
                                        customer.setUserName(user.getTrueName());
                                        tcustomerService.updateNotNull(customer);
                                }
                        }
                        resultmap.put("state", "success");
                        resultmap.put("mesg", "操作成功");
                        return resultmap;
                } catch (Exception e) {
                        e.printStackTrace();
                        resultmap.put("state", "fail");
                        resultmap.put("mesg", "操作失败，系统异常");
                        return resultmap;
                }
        }
        @ResponseBody
        @RequestMapping(value = "/deleteCustomer")
        @RequiresPermissions(value = {"客户管理"})
        public Map<String, Object> deleteuser(Tcustomer customer) {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
                try {
                        if (customer.getId() != null && !customer.getId().equals(0)) {
                                Tcustomer customer2 = tcustomerService.selectByKey(customer.getId());
                                if (customer2 == null) {
                                        resultmap.put("state", "fail");
                                        resultmap.put("mesg", "删除失败,无法找到该记录");
                                        return resultmap;
                                } else {

                                        tcustomerService.delete(customer.getId());
                                }
                        } else {
                                resultmap.put("state", "fail");
                                resultmap.put("mesg", "删除失败");
                        }


                        resultmap.put("state", "success");
                        resultmap.put("mesg", "删除成功");
                        return resultmap;
                } catch (Exception e) {
                        e.printStackTrace();
                        resultmap.put("state", "fail");
                        resultmap.put("mesg", "删除失败，系统异常");
                        return resultmap;
                }
        }
        @ResponseBody
        @RequestMapping(value = "/setMyCustomer")
        @RequiresPermissions(value = {"客户管理"})
        public Map<String, Object> setMyCustomer(Tcustomer customer,HttpServletRequest request) {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
                try {
                        if (customer.getId() != null && !customer.getId().equals(0)) {
                                Tcustomer customer2 = tcustomerService.selectByKey(customer.getId());
                                if (customer2 == null) {
                                        resultmap.put("state", "fail");
                                        resultmap.put("mesg", "设置失败,无法找到该记录");
                                        return resultmap;
                                } else {
                                        //获取用户信息
                                       Tuser user=(Tuser) request.getSession().getAttribute("currentUser");
                                        customer2.setUserId(user.getId()+"");
                                        customer2.setUserName(user.getTrueName());
                                        customer2.setUpdateTime(format.format(new Date()));
                                        tcustomerService.updateNotNull(customer2);
                                }
                        } else {
                                resultmap.put("state", "fail");
                                resultmap.put("mesg", "设置失败");
                        }


                        resultmap.put("state", "success");
                        resultmap.put("mesg", "设置成功");
                        return resultmap;
                } catch (Exception e) {
                        e.printStackTrace();
                        resultmap.put("state", "fail");
                        resultmap.put("mesg", "设置失败，系统异常");
                        return resultmap;
                }
        }

        @ResponseBody
        @RequestMapping(value = "/moveMyCustomer")
        @RequiresPermissions(value = {"客户管理"})
        public Map<String, Object> moveMyCustomer(Tcustomer customer,HttpServletRequest request) {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
                try {
                        if (customer.getId() != null && !customer.getId().equals(0)) {
                                Tcustomer customer2 = tcustomerService.selectByKey(customer.getId());
                                if (customer2 == null) {
                                        resultmap.put("state", "fail");
                                        resultmap.put("mesg", "设置失败,无法找到该记录");
                                        return resultmap;
                                } else {
                                        customer2.setUserId("");
                                        customer2.setUserName("");
                                        customer2.setUpdateTime(format.format(new Date()));
                                        tcustomerService.updateNotNull(customer2);
                                }
                        } else {
                                resultmap.put("state", "fail");
                                resultmap.put("mesg", "设置失败");
                        }


                        resultmap.put("state", "success");
                        resultmap.put("mesg", "设置成功");
                        return resultmap;
                } catch (Exception e) {
                        e.printStackTrace();
                        resultmap.put("state", "fail");
                        resultmap.put("mesg", "设置失败，系统异常");
                        return resultmap;
                }
        }

        @ResponseBody
        @RequestMapping(value = "/selectCustomerById")
        @RequiresPermissions(value = {"客户管理"})
        public Map<String, Object> selectRoleById(Tcustomer customer) {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
                try {
                        if (customer.getId() != null && !customer.getId().equals(0)) {
                                customer = tcustomerService.selectByKey(customer.getId());
                                if (customer == null) {
                                        resultmap.put("state", "fail");
                                        resultmap.put("mesg", "无法找到该记录");
                                        return resultmap;
                                }
                        } else {
                                resultmap.put("state", "fail");
                                resultmap.put("mesg", "无法找到该记录的id");
                                return resultmap;
                        }

                        resultmap.put("customer", customer);
                        resultmap.put("state", "success");
                        resultmap.put("mesg", "获取成功");
                        return resultmap;
                } catch (Exception e) {
                        e.printStackTrace();
                        resultmap.put("state", "fail");
                        resultmap.put("mesg", "获取失败，系统异常");
                        return resultmap;
                }
        }

        @ResponseBody
        @RequestMapping(value = "/getGroupList")
        @RequiresPermissions(value = {"客户管理"})
        public Map<String, Object> getGroupList() {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
                try {
                        //获取客户分类信息
                        Example deptExample = new Example(Tgroup.class);
                        List<Tgroup> groupList = groupService.selectByExample(deptExample);
                        resultmap.put("groupList",groupList);//客户分类列表
                        resultmap.put("state", "success");
                        resultmap.put("mesg", "获取成功");
                        return resultmap;
                } catch (Exception e) {
                        e.printStackTrace();
                        resultmap.put("state", "fail");
                        resultmap.put("mesg", "获取失败，系统异常");
                        return resultmap;
                }
        }
        @ResponseBody
        @RequestMapping(value = "/getUserList")
        @RequiresPermissions(value = {"客户管理"})
        public Map<String, Object> getUserList() {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
                try {
                        //获取客户分类信息
                        Example deptExample = new Example(Tuser.class);
                        List<Tuser> groupList = tuserService.selectByExample(deptExample);
                        resultmap.put("userList",groupList);//客户分类列表
                        resultmap.put("state", "success");
                        resultmap.put("mesg", "获取成功");
                        return resultmap;
                } catch (Exception e) {
                        e.printStackTrace();
                        resultmap.put("state", "fail");
                        resultmap.put("mesg", "获取失败，系统异常");
                        return resultmap;
                }
        }
        //获取当前需要跟进的客户信息，在首页显示出来
        @ResponseBody
        @RequestMapping(value = "/messageInfo")
        @RequiresPermissions(value = {"客户管理"})
        public Map<String, Object> messageInfo(HttpServletRequest request) {
                LinkedHashMap<String, Object> resultmap = new LinkedHashMap<String, Object>();
                List<Tcustomer> tcustomerList=new ArrayList<>();
                try {
                        //获取客户信息
                        Example customer = new Example(Tcustomer.class);
                        //获取当前登录用户信息
                        Tuser user=(Tuser) request.getSession().getAttribute("currentUser");
                        customer.and().andEqualTo("userId",user.getId());
                        List<Tcustomer> clist = tcustomerService.selectByExample(customer);

                        if (clist.size()>0){
                                for(Tcustomer tc:clist){
                                        Example trail = new Example(Ttrail.class);
                                        trail.and().andEqualTo("customerId",tc.getId());
                                       String day1=format2.format(new Date());
                                        Calendar c = Calendar.getInstance();
                                        c.setTime(new Date());
                                        c.add(Calendar.DAY_OF_MONTH, 7);// 今天+7天
                                        String day2=format2.format(c.getTime());
                                        trail.and().andBetween("nextTime",day1,day2);
                                        //trail.and().andLessThanOrEqualTo("nextTime",day2);
                                        //trail.and().andGreaterThanOrEqualTo("nextTime",day1);
                                        List<Ttrail> listTrail =ttrailService .selectByExample(trail);
                                        //如果有需要1天内跟进的客户，则返回客户
                                        if (listTrail!=null&& listTrail.size()>0){
                                                tcustomerList.add(tc);
                                        }
                                }
                        }
                        //获取当前需要跟进的客户
                        resultmap.put("message",tcustomerList);//客户分类列表
                        resultmap.put("state", "success");
                        resultmap.put("mesg", "获取成功");
                        return resultmap;
                } catch (Exception e) {
                        e.printStackTrace();
                        resultmap.put("state", "fail");
                        resultmap.put("mesg", "获取失败，系统异常");
                        return resultmap;
                }
        }



}
